from requests.cookies import RequestsCookieJar


def get_parameter(request, key):
    # 获取请求参数
    value = None
    if request.method == 'POST':
        value = request.json.get(key)
    elif request.method == 'GET':
        value = request.args.get(key)
    return value


def get_cookie_jar(cookies):
    cookie_jar = RequestsCookieJar()
    for cookie in cookies:
        cookie_jar.set(cookie['name'], cookie['value'])
    return cookie_jar


def get_image_path(image_path):
    fix = "?x-oss-process=image/format,webp/resize,w_130,h_130,m_fixed"
    image_type = image_path[-4:]
    if image_type != "jpeg" and image_type != "JPEG":
        image_type = image_path[-3:]
    real_image_path = "https://cube.elemecdn.com/" + image_path[0] + "/" + image_path[1:3] + "/" \
                      + image_path[3:] + "." + image_type + fix
    return real_image_path
